package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.RouteOperation;
import com.efast.dmom.mes.entity.RouteOperationEntity;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.RouteOperationService;

/**
 * To achieve the operation's new, delete, modify, query methods
 * @author WJ
 * @Data 2020年2月18日
 *
 */

@Controller
@RequestMapping("/routeOperation")
public class RouteOperationController {
	
	@Autowired
	private RouteOperationService routeOperationService;
	
	@RequestMapping(value = "/operateByRouteOperation")
	public @ResponseBody ResultBean operateByRouteOperation(@RequestBody RouteOperation routeOperation) {
		
		RouteOperationEntity entity = routeOperation.getInnerData();
		// Determine the new
		if (routeOperation.getModificationFlag() == IModificationFlags.NEW) {
			return routeOperationService.save(routeOperation);
			// Judge update
		} else if (routeOperation.getModificationFlag() == IModificationFlags.MODIFIED) {
			return routeOperationService.update(routeOperation);
			// Judge to delete
		} else if (routeOperation.getModificationFlag() == IModificationFlags.DELETED) {
			return routeOperationService.delete(routeOperation);
		}
		return null;
	}

	// get routeOperation by id
	@RequestMapping(value = "/getRouteOperationById/{id}")
	public @ResponseBody RouteOperation getRouteOperationById(@PathVariable long id) {
		return routeOperationService.getById(id);
	}

	// get routeOperation by name
	@RequestMapping(value = "/getRouteOperationByName/{name}")
	public @ResponseBody RouteOperation getRouteOperationByName(@PathVariable String name) {
		return routeOperationService.getByName(name);
	}
	
	//get all routeOperation
	@RequestMapping(value = "/getAllRouteOperation")
	public @ResponseBody List<RouteOperation> getAllRouteOperation() {
		return routeOperationService.getAllRouteOperation();
	}
	
}
